package net.lesscoding.producer;

import net.lesscoding.common.Const;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

/**
 * @author eleven
 * @date 2024/6/2 11:07
 * @apiNote
 */
public class FilterByTagProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("pg");
        producer.setNamesrvAddr(Const.TS_NAME_SRV_ADDR_OS1);
        producer.start();

        String[] tags = {"Tag-A", "Tag-B", "Tag-C"};
        for (int i = 0; i < 10; i++) {
            byte[] body = ("Hi," + i).getBytes();
            String tag = tags[i % tags.length];
            Message msg = new Message("filterByTagTopic", tag, body);
            System.out.println(producer.send(msg));
        }
        producer.shutdown();
    }
}
